class CustomError extends Error {
  constructor(message) {
    super(message);
    this.name = this.constructor.name;
    Error.captureStackTrace(this, this.constructor);
  }
}

class AppError extends CustomError {
  constructor(message, code = 0, data = {}) {
    super(message);
    this.message = message;
    this.code = code;
    this.data = data;
  }

  getMessage() {
    return this.message;
  }

  setMessage(...values) {
    this.message = values.join(" ");
    return this;
  }

  getData() {
    return this.data;
  }

  setData(...values) {
    if (values.length > 0) {
      if (values.length > 1) {
        this.data = values;
      } else {
        [this.data] = values;
      }
    }
    return this;
  }

  getCode() {
    return this.code;
  }

  setCode(value) {
    this.code = value;
    return this;
  }
}

class AppRuntimeError extends AppError {}

class AppLogicError extends AppError {}

class AuthError extends AppRuntimeError {}
class UserRuntimeError extends AppRuntimeError {}
class ClientRuntimeError extends AppRuntimeError {}

class ScheduleRuntimeError extends AppRuntimeError {}

export {
  AppError,
  AppRuntimeError,
  AppLogicError,
  AuthError,
  UserRuntimeError,
  ClientRuntimeError,
  ScheduleRuntimeError
};
export default AppError;
